package chapter5.beanNameaware_interface;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.support.GenericXmlApplicationContext;

public class LoggingBean implements BeanNameAware {
	public static final Log log = LogFactory.getLog(LoggingBean.class);
	private String beanName = null;

	@Override
	public void setBeanName(String arg0) {
		this.beanName = arg0;
	}

	public void someOperation() {
		if (log.isInfoEnabled()) {
			log.info("Bean [" + beanName + "] - someOperation()");
		}
	}

	public static void main(String[] args) {
		GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
		ctx.load("classpath:chapter5/beanNameaware_interface/logging.xml");
		ctx.refresh();

		LoggingBean bean = (LoggingBean) ctx.getBean("loggingBean");
		bean.someOperation();
	}
}
